# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 10:13:50 2024

@author: 刘翼
"""


import cv2

img = cv2.imread(r"C:\Users\Public\opencv\Figure\Flag.jpg",1)
cv2.imshow("Original image", img)

blurred = cv2.GaussianBlur(img, (3, 3), 0)
gray = cv2.cvtColor(blurred, cv2.COLOR_RGB2GRAY)

edge_output = cv2.Canny(gray, 220, 250)
cv2.imshow("Canny Edge", edge_output)

contours, hierarchy = cv2.findContours(edge_output, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
for i,contour in enumerate(contours):
    cv2.drawContours(img, contours, -1, (0, 0, 255),1)
    cv2.imshow('Output image', img) 

cv2.waitKey(0)
cv2.destroyAllWindows()

